package com.ganee.baselib.httprequest.interceptor;

import android.text.TextUtils;


import com.ganee.baselib.httprequest.cache.ACache;
import com.ganee.baselib.httprequest.cache.EnumKey;
import com.ganee.baselib.httprequest.utils.AppUtils;
import com.ganee.baselib.httprequest.utils.Utils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;


/**
 *  头部拦截器
 */
public class HeaderInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        String token = ACache.get(Utils.getContext()).getAsString(EnumKey.User.USER_TOKEN);
        if (TextUtils.isEmpty(token)) {
            token = "";
        }
        Request request = original.newBuilder()
                .header("access_token", token)
                .method(original.method(), original.body())
                .build();
        return chain.proceed(request);

    }

}